package com.todo.strategy.online.application.api.controller;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.strategy.online.application.service.pipeline.MemoTemplatePipelineService;
import com.todo.strategy.online.service.api.pipeline.MemoPipelineApi;
import com.todo.strategy.online.service.api.pipeline.request.InsertMemoTemplateRequest;
import com.todo.strategy.online.service.api.pipeline.request.RemoteMemoTemplateRequest;
import com.todo.strategy.online.service.api.pipeline.request.UpdateMemoTemplateRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/3/1 15:20
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/api/pipeline/memo")
@Tag(name = "服务端-备忘录模板同步接口", description = "服务端-备忘录模板同步接口")
public class MemoPipelineApiController implements MemoPipelineApi {

    @Resource
    private MemoTemplatePipelineService memoTemplatePipelineService;

    @Override
    @Operation(summary = "插入模板")
    @PostMapping("/insertMemoTemplate")
    public BizResponse<Boolean> insertMemoTemplate(@RequestBody InsertMemoTemplateRequest request) {
        if (request == null || !request.isCheck()) {
            return BizResponse.paramError();
        }
        Boolean result = memoTemplatePipelineService.insertMemoTemplate(request.getBusinessId(), request.getOriginData());
        return BizResponse.success(result);
    }

    @Override
    @Operation(summary = "更新模板")
    @PostMapping("/updateMemoTemplate")
    public BizResponse<Boolean> updateMemoTemplate(@RequestBody UpdateMemoTemplateRequest request) {
        if (request == null || !request.isCheck()) {
            return BizResponse.paramError();
        }
        Boolean result = memoTemplatePipelineService.updateMemoTemplate(request.getBusinessId(), request.getOriginData());
        return BizResponse.success(result);
    }

    @Override
    @Operation(summary = "删除模板")
    @PostMapping("/remoteMemoTemplate")
    public BizResponse<Boolean> remoteMemoTemplate(@RequestBody RemoteMemoTemplateRequest request) {
        if (request == null || !request.isCheck()) {
            return BizResponse.paramError();
        }
        Boolean result = memoTemplatePipelineService.remoteMemoTemplate(request.getBusinessId());
        return BizResponse.success(result);
    }

}
